//
//  FillInInformationVC.m
//  MRBang
//
//  Created by 铅笔 on 16/4/19.
//  Copyright © 2016年 杭州易网新科技. All rights reserved.
//

#import "FillInInformationVC.h"

#import "PickViewSelect.h"

#import "PickerView.h"//年龄选择 picker view

#import "SupplementaryInformationVC.h"

#define CELLHEIGHT 88*PROPORTION_WIDTH

@interface FillInInformationVC ()<UITableViewDataSource,UITableViewDelegate,pickViewStrDelegate,UITextFieldDelegate>

{
    UIButton *button_man,*button_woman;//性别
    int pathSex;//传递性别
    UILabel *label_man,*label_woman;
    UITextField *textField_name;//设置名称
    NSString *str_name;//记录姓名
    BOOL isEditName;//标记是否是在编辑姓名
    
    UIView *view_choseAgeBG,*view_cover;//选择 年龄的view
    UIButton *button_nextAction;//进入下一个页面的按钮
    UIButton *button_startTime,*button_endTime;
    //0 出生日期  1 开始时间 3 结束时间
    int recordChoseWhoTime;//记录时选择谁的时间
}

@property(nonatomic,strong) PickViewSelect *pickView;
@property(nonatomic,strong) PickerView *pickerView;//时间选择

@property (nonatomic,strong) UITableView *tableView_fillInfo;

@property (nonatomic,strong) NSMutableArray *mutableArray_content;//修改每一行 信息后

@property (nonatomic,strong) UIDatePicker *datePicker;//picker view
@property (strong, nonatomic)  UIView *buttonView;//button view

@property (nonatomic,strong) NSMutableDictionary *dic_xinfoAll;//存放所有数据
//@property (nonatomic,strong) NSDictionary *dic_xinfoAll;//存放所有数据

@end

@implementation FillInInformationVC

- (NSMutableArray *) mutableArray_content
{
    if (_mutableArray_content==nil) {
        _mutableArray_content = [[NSMutableArray alloc] init];
    }
    return _mutableArray_content;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"填写资料";
    self.view.backgroundColor = COLOR_EVERYVIEWBG;
    
//    str_name = @"钱多多";
    
    //网络请求
    [self DataSourceRequestMemberXinfoView];
    
    self.mutableArray_content = [@[@"1990-12-01",@"中国",@"本科",@"未婚",@"身份证",@"填写",@"填写",@"填写",@"填写",@"填写",@"填写",@"填写",@"填写"]  mutableCopy];
    
    [self initWithFillInInformationVCSubviews];

    isEditName = NO;
    //注册键盘通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    recordChoseWhoTime = 3;
    
    if (self.dic_xinfoAll[@"isortherxyk"]) {
        pathSex = [self.dic_xinfoAll[@"isortherxyk"] intValue];
    }
    else
    {
        pathSex = 2;//标记 性别
    }
}

#pragma mark --- 创建视图界面
- (void) initWithFillInInformationVCSubviews
{
    self.tableView_fillInfo = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-93*PROPORTION_WIDTH-20)];
    [self.view addSubview:self.tableView_fillInfo];
    self.tableView_fillInfo.dataSource = self;
    self.tableView_fillInfo.delegate = self;
    self.tableView_fillInfo.showsVerticalScrollIndicator = NO;
    self.tableView_fillInfo.separatorStyle =UITableViewCellSeparatorStyleNone;
    self.tableView_fillInfo.backgroundColor = COLOR_EVERYVIEWBG;
    
    //下一步 button
    button_nextAction = [[UIButton alloc] initWithFrame:CGRectMake(48*PROPORTION_WIDTH,kScreenHeight-93*PROPORTION_WIDTH-10,kScreenWidth - 48*PROPORTION_WIDTH*2, 93*PROPORTION_WIDTH)];
    [self.view addSubview:button_nextAction];
    
    [button_nextAction setBackgroundImage:[UIImage imageNamed:@"button_next"] forState:UIControlStateNormal];
    
    [button_nextAction addTarget:self action:@selector(doNextAction) forControlEvents:UIControlEventTouchUpInside];
}

#pragma  mark ----UITableViewDataSource
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 15;
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *cellFillInInformationID = @"cellFillInInformationID";
    
    UITableViewCell *cell_fillInfo = [tableView cellForRowAtIndexPath:indexPath];
    if (cell_fillInfo==nil) {
        cell_fillInfo = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellFillInInformationID];
    }
    
    UIView *view_line = [[UIView alloc] initWithFrame:CGRectMake(27*PROPORTION_WIDTH, CELLHEIGHT-1, kScreenWidth, 1.0)];
    [cell_fillInfo.contentView addSubview:view_line];
    view_line.backgroundColor = [BaseViewController colorWithHexString:@"#EEEFF1"];
    
    cell_fillInfo.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSArray *array_title = @[@"*中文姓名",@"*性别",@"*出生日期",@"*国籍",@"*教育程度",@"*婚姻状况",@"*证件类型",@"*证件号",@"*证件有效期",@"*签发机关",@"*移动电话",@"*住宅地址",@"*邮政编码",@"*住宅电话",@"*邮箱"];
    
    UILabel *label_leftTitle = [[UILabel alloc] initWithFrame:CGRectMake(27*PROPORTION_WIDTH, 22*PROPORTION_WIDTH, 170*PROPORTION_WIDTH, 20)];
    [cell_fillInfo addSubview:label_leftTitle];
    
    label_leftTitle.font = [UIFont systemFontOfSize:30*PROPORTION_WIDTH];
    label_leftTitle.textColor = [BaseViewController colorWithHexString:@"#666666"];
    
    label_leftTitle.text = array_title[indexPath.row];
    
    NSRange range1 = [label_leftTitle.text rangeOfString: @"*"];
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString: label_leftTitle.text];
    [attribute addAttributes: @{NSForegroundColorAttributeName:[UIColor redColor]}range: range1];
    
    [attribute addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30*PROPORTION_WIDTH] range:range1];
    [label_leftTitle setText: label_leftTitle.text];
    [label_leftTitle setAttributedText: attribute];
    
    //右侧 文字
    UILabel *label_rightContent = [[UILabel alloc] initWithFrame:CGRectMake(label_leftTitle.right+5, 22*PROPORTION_WIDTH, 448*PROPORTION_WIDTH, 20)];
    [cell_fillInfo addSubview:label_rightContent];
    label_rightContent.font = [UIFont systemFontOfSize:30*PROPORTION_WIDTH];
    label_rightContent.textColor = [BaseViewController colorWithHexString:@"#AAAAAA"];

    if (indexPath.row==0) {
        //姓名
        //UITextField
       textField_name = [[UITextField alloc] initWithFrame:label_rightContent.frame];
        [cell_fillInfo addSubview:textField_name];
        textField_name.font = [UIFont systemFontOfSize:30*PROPORTION_WIDTH];
        textField_name.textColor = [BaseViewController colorWithHexString:@"#AAAAAA"];
        textField_name.delegate = self;
        textField_name.tag = 0;
        
        if (self.dic_xinfoAll[@"name"]) {
            textField_name.text = self.dic_xinfoAll[@"name"];
        }
        else
        {
            textField_name.placeholder = @"填写";

        }
    }
    if (indexPath.row==1) {
        //性别
        //男
        button_man = [[UIButton alloc] initWithFrame:CGRectMake(label_leftTitle.right+5,27*PROPORTION_WIDTH, 38*PROPORTION_WIDTH, 38*PROPORTION_WIDTH)];
        [cell_fillInfo.contentView addSubview:button_man];
        
        button_man.tag = 33;
        [button_man addTarget:self action:@selector(choseSexManOrWoman:) forControlEvents:UIControlEventTouchUpInside];
        
        label_man = [[UILabel alloc] initWithFrame:CGRectMake(button_man.right+5, 22*PROPORTION_WIDTH, 30,20)];
        [cell_fillInfo.contentView addSubview:label_man];
        label_man.text = @"男";
        label_man.textColor = [BaseViewController colorWithHexString:@"#AAAAAA"];
        label_man.font = [UIFont systemFontOfSize:Font_SIZE_14];
        
        //女
        button_woman = [[UIButton alloc] initWithFrame:CGRectMake(label_man.right+10,27*PROPORTION_WIDTH, button_man.width, button_man.height)];
        [cell_fillInfo.contentView addSubview:button_woman];
        button_woman.tag = 34;
        [button_woman addTarget:self action:@selector(choseSexManOrWoman:) forControlEvents:UIControlEventTouchUpInside];
        
        label_woman = [[UILabel alloc] initWithFrame:CGRectMake(button_woman.right+5, 22*PROPORTION_WIDTH, 30,20)];
        [cell_fillInfo.contentView addSubview:label_woman];
        label_woman.text = @"女";
        label_woman.textColor = [BaseViewController colorWithHexString:@"#AAAAAA"];
        label_woman.font = [UIFont systemFontOfSize:Font_SIZE_14];
    }
    
    if (pathSex==1) {
        [button_man setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
        [button_woman setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
    }
    if (pathSex==0)
    {
        [button_woman setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
        [button_man setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
    }
    if (pathSex==2)
    {
        [button_woman setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
        [button_man setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
    }

    //button
    if (indexPath.row==2||indexPath.row==3||indexPath.row==4||indexPath.row==5||indexPath.row==6) {
        
        UIButton *button_rightArrow = [[UIButton alloc] initWithFrame:CGRectMake(kScreenWidth-30, 12, 20, 20)];
        [cell_fillInfo.contentView addSubview:button_rightArrow];
        [button_rightArrow setImage:[UIImage imageNamed:@"return_right"] forState:UIControlStateNormal];
        
        label_rightContent.text = self.mutableArray_content[indexPath.row-2];

        
        if (indexPath.row==2) {
            if (self.dic_xinfoAll[@"brithday"]) {
                label_rightContent.text = self.dic_xinfoAll[@"brithday"];
            }
        }
        
        if (indexPath.row==3) {
            if (self.dic_xinfoAll[@"nationality"]) {
                label_rightContent.text = self.dic_xinfoAll[@"nationality"];
            }

        }

        if (indexPath.row==4) {
            if (self.dic_xinfoAll[@"educationlevel"]) {
                
                NSString *str_educationlevel;
                int cardtype = [self.dic_xinfoAll[@"educationlevel"] intValue];
                if (cardtype == 1) {
                    
                    str_educationlevel = @"硕士及以上";
                }
                if (cardtype == 2) {
                    
                    str_educationlevel = @"本科";
                }
                if (cardtype == 3) {
                    
                    str_educationlevel = @"大专";
                }
                if (cardtype == 4) {
                    
                    str_educationlevel = @"高中/中专";
                }
                if (cardtype == 5) {
                    
                    str_educationlevel =@"初中及以下";
                }

                label_rightContent.text = [NSString stringWithFormat:@"%@",str_educationlevel];
            }

        }
        if (indexPath.row==5) {
            if (self.dic_xinfoAll[@"ismarriage"]) {
                
                NSString *str_ismarriage;
                int cardtype = [self.dic_xinfoAll[@"ismarriage"] intValue];
                if (cardtype == 1) {
                    
                    str_ismarriage = @"未婚";
                }
                if (cardtype == 2) {
                    
                    str_ismarriage = @"已婚";
                }

                label_rightContent.text = [NSString stringWithFormat:@"%@",str_ismarriage];
            }
        }

        if (indexPath.row==6) {
            if (self.dic_xinfoAll[@"cardtype"]) {
                
                NSString *str_cardtype;
                int cardtype = [self.dic_xinfoAll[@"cardtype"] intValue];
                if (cardtype == 1) {
             
                    str_cardtype = @"身份证";
                }
                if (cardtype == 2) {
                    
                    str_cardtype = @"护照";
                }
                if (cardtype == 3) {
                    
                    str_cardtype = @"军官证";
                }
                if (cardtype == 4) {
          
                    str_cardtype = @"港澳台证件";
                }
                if (cardtype == 5) {
                   
                    str_cardtype =@"其他证件";
                }
                
                label_rightContent.text = [NSString stringWithFormat:@"%@",str_cardtype];
            }
        }
    }
    if (indexPath.row==8) {

        [self.mutableArray_content replaceObjectAtIndex:indexPath.row-2 withObject:@"8"];
      
        //开始日期
        button_startTime = [[UIButton alloc] initWithFrame:CGRectMake(label_rightContent.x,10,200*PROPORTION_WIDTH, label_rightContent.height)];
        [cell_fillInfo addSubview:button_startTime];
        
        button_startTime.layer.borderColor = COLOT_TEXTGRAY.CGColor;
        button_startTime.layer.borderWidth = 1.0;
        
        [button_startTime setTitleColor:[BaseViewController colorWithHexString:@"#AAAAAA"] forState:UIControlStateNormal];
        
        [button_startTime.titleLabel setFont:[UIFont systemFontOfSize:30*PROPORTION_WIDTH]];
        button_startTime.tag = 30;
        
        [button_startTime addTarget:self action:@selector(choseTimeAction:) forControlEvents:UIControlEventTouchUpInside];
        
        //结束日期
        button_endTime = [[UIButton alloc] initWithFrame:CGRectMake(button_startTime.right+20*PROPORTION_WIDTH,button_startTime.y,button_startTime.width, button_startTime.height)];
        [cell_fillInfo addSubview:button_endTime];
        [button_endTime.titleLabel setFont:[UIFont systemFontOfSize:30*PROPORTION_WIDTH]];
        
        button_endTime.layer.borderColor = COLOT_TEXTGRAY.CGColor;
        button_endTime.layer.borderWidth = 1.0;
        
        [button_endTime setTitleColor:[BaseViewController colorWithHexString:@"#AAAAAA"] forState:UIControlStateNormal];
        
        button_endTime.tag = 31;
        
        [button_endTime addTarget:self action:@selector(choseTimeAction:) forControlEvents:UIControlEventTouchUpInside];
        
        if ([self.dic_xinfoAll[@"cardtime"] containsString:@"-"]) {
            
            //有日期的时候
            [button_startTime setTitle:[self.dic_xinfoAll[@"cardtime"] substringToIndex:10] forState:UIControlStateNormal];
            
            [button_endTime setTitle:[self.dic_xinfoAll[@"cardtime"] substringFromIndex:11] forState:UIControlStateNormal];
        }
        else
        {
            //没有日期的时候
            [self.dic_xinfoAll setObject:@"2010.10.10-2011.10.10"  forKey:@"cardtime"];
            
            [button_startTime setTitle:[self.dic_xinfoAll[@"cardtime"] substringToIndex:10] forState:UIControlStateNormal];
            
            [button_endTime setTitle:[self.dic_xinfoAll[@"cardtime"] substringFromIndex:11] forState:UIControlStateNormal];
        }
    }
    
    if (indexPath.row==7||indexPath.row==9||indexPath.row==10||indexPath.row==11||indexPath.row==12||indexPath.row==13||indexPath.row==14) {
        
        //UITextField
        UITextField *textField_finll = [[UITextField alloc] initWithFrame:label_rightContent.frame];
        [cell_fillInfo addSubview:textField_finll];
        textField_finll.font = [UIFont systemFontOfSize:30*PROPORTION_WIDTH];
        textField_finll.textColor = [BaseViewController colorWithHexString:@"#AAAAAA"];
        textField_finll.tag = indexPath.row;
        textField_finll.delegate = self;
        
        textField_finll.placeholder = self.mutableArray_content[indexPath.row-2];
        
        if (indexPath.row==7) {
            if ([self.dic_xinfoAll[@"cardnum"] length]!=0) {
                textField_finll.text = [NSString stringWithFormat:@"%@",self.dic_xinfoAll[@"cardnum"]];
                [self.mutableArray_content replaceObjectAtIndex:indexPath.row-2 withObject:self.dic_xinfoAll[@"cardnum"]];
            }
        }
        
                //签发机关
        if (indexPath.row==9) {
            if ([self.dic_xinfoAll[@"fzjg"] length]!=0) {

                textField_finll.text = [NSString stringWithFormat:@"%@",self.dic_xinfoAll[@"fzjg"]];
                [self.mutableArray_content replaceObjectAtIndex:indexPath.row-2 withObject:self.dic_xinfoAll[@"fzjg"]];

            }
        }
        
        if (indexPath.row==10) {
            if ([self.dic_xinfoAll[@"mobile"] length]!=0) {

                textField_finll.text = [NSString stringWithFormat:@"%@",self.dic_xinfoAll[@"mobile"]];
                [self.mutableArray_content replaceObjectAtIndex:indexPath.row-2 withObject:self.dic_xinfoAll[@"mobile"]];
            }
        }
        
        if (indexPath.row==11) {
            if ([self.dic_xinfoAll[@"address"] length]!=0) {

                textField_finll.text = [NSString stringWithFormat:@"%@", self.dic_xinfoAll[@"address"]];
                 [self.mutableArray_content replaceObjectAtIndex:indexPath.row-2 withObject:self.dic_xinfoAll[@"address"]];
            }
        }
        if (indexPath.row==12) {
            if ([self.dic_xinfoAll[@"postcode"] length]!=0) {

                  textField_finll.text = [NSString stringWithFormat:@"%@", self.dic_xinfoAll[@"postcode"]];
                [self.mutableArray_content replaceObjectAtIndex:indexPath.row-2 withObject:self.dic_xinfoAll[@"postcode"]];
            }
        }
        if (indexPath.row==13) {
            if ([self.dic_xinfoAll[@"tel"] length]!=0) {

                 textField_finll.text = [NSString stringWithFormat:@"%@", self.dic_xinfoAll[@"tel"]];
                [self.mutableArray_content replaceObjectAtIndex:indexPath.row-2 withObject:self.dic_xinfoAll[@"tel"]];

            }
        }
        if (indexPath.row==14) {
            if ([self.dic_xinfoAll[@"email"] length]!=0) {

                 textField_finll.text = [NSString stringWithFormat:@"%@", self.dic_xinfoAll[@"email"]];
                
                [self.mutableArray_content replaceObjectAtIndex:indexPath.row-2 withObject:self.dic_xinfoAll[@"email"]];
            }
        }
    }
    return cell_fillInfo;
}

//选择 时间
- (void) choseTimeAction:(UIButton *) sender
{
    //将键盘 退出
    [self commentTableViewTouchInSide];
    
    if (sender.tag==30) {
        recordChoseWhoTime = 1;
    }
    if (sender.tag==31) {
        recordChoseWhoTime = 2;
    }

    [self initWithChoseAgeSubviews];
}

//文字内容替换
- (void) textFieldDidEndEditing:(UITextField *)textField
{
    if ( textField != textField_name && textField.text.length!=0) {
        
        if (textField.tag == 7) {
            [self.dic_xinfoAll setObject:textField.text forKey:@"cardnum"];
        }
        if (textField.tag == 8) {
         [self.dic_xinfoAll setObject:textField.text forKey:@"cardtime"];
        }
        if (textField.tag == 9) {
            [self.dic_xinfoAll setObject:textField.text forKey:@"fzjg"];

        }
        if (textField.tag == 10) {
            [self.dic_xinfoAll setObject:textField.text forKey:@"mobile"];

        }
        if (textField.tag == 11) {
             [self.dic_xinfoAll setObject:textField.text forKey:@"address"];
        }
        if (textField.tag == 12) {
             [self.dic_xinfoAll setObject:textField.text forKey:@"postcode"];
        }
        if (textField.tag == 13) {
            [self.dic_xinfoAll setObject:textField.text forKey:@"tel"];
        }
        if (textField.tag == 14) {
            
            [self.dic_xinfoAll setObject:textField.text forKey:@"email"];
        }
        
        [self.mutableArray_content replaceObjectAtIndex:textField.tag-2 withObject:textField.text];
        [self.tableView_fillInfo reloadData];
    }
    else
    {
        [self.dic_xinfoAll setObject:textField_name.text forKey:@"name"];
    }
}

- (void) textFieldDidBeginEditing:(UITextField *)textField
{
    
    if (textField==textField_name) {
       
        isEditName = YES;
    }
    else
    {
        isEditName = NO;
    }
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return CELLHEIGHT;
}

- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self commentTableViewTouchInSide];
    
    if (indexPath.row==2) {
        
        recordChoseWhoTime = 0;
        
        [self initWithChoseAgeSubviews];
    }
    
    if (indexPath.row==3||indexPath.row==4||indexPath.row==5||indexPath.row==6) {
         NSArray *array_allData = @[@[@"中国",@"国外"],@[@"硕士及以上",@"本科",@"大专",@"高中/中专",@"初中/以下"],@[@"未婚",@"已婚"],@[@"身份证",@"护照",@"军官证",@"港澳台证件",@"其他证件"]];
        
        _pickView =[[PickViewSelect alloc]initWithDataArr:array_allData[indexPath.row-3] andRowIndex:(int)(indexPath.row-2)];
        _pickView.delegate = self;
        [self.view addSubview:_pickView];
        
        
    }
    if (indexPath.row==7||indexPath.row==8||indexPath.row==9||indexPath.row==10||indexPath.row==11||indexPath.row==12||indexPath.row==13||indexPath.row==14)
    {
        
    }

}

#pragma mark  --- 点击tableView 收回键盘
- (void)commentTableViewTouchInSide
{
    UITextField *textField_temp7 = (UITextField *)[self.view viewWithTag:7];
    
    [textField_temp7 resignFirstResponder];
    
    UITextField *textField_temp8 = (UITextField *)[self.view viewWithTag:8];
    
    [textField_temp8 resignFirstResponder];
    
    UITextField *textField_temp9 = (UITextField *)[self.view viewWithTag:9];
    
    [textField_temp9 resignFirstResponder];
    
    UITextField *textField_temp10 = (UITextField *)[self.view viewWithTag:10];
    
    [textField_temp10 resignFirstResponder];
    
    UITextField *textField_temp11 = (UITextField *)[self.view viewWithTag:11];
    
    [textField_temp11 resignFirstResponder];
    
    UITextField *textField_temp12 = (UITextField *)[self.view viewWithTag:12];
    
    [textField_temp12 resignFirstResponder];
    
    UITextField *textField_temp13 = (UITextField *)[self.view viewWithTag:13];
    
    [textField_temp13 resignFirstResponder];
    
    UITextField *textField_temp14 = (UITextField *)[self.view viewWithTag:14];
    
    [textField_temp14 resignFirstResponder];
    
    [textField_name resignFirstResponder];
}

- (void) touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

#pragma mark --- 创建选择年龄的 界面
- (void) initWithChoseAgeSubviews
{
    //背景view
    view_cover = [[UIView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:view_cover];
    view_cover.backgroundColor = [UIColor clearColor];
    
    //添加手势 用于移除
    UITapGestureRecognizer *tapGestureView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeChoseAgeBGBgView)];
    [view_cover addGestureRecognizer:tapGestureView];
    
    //bg
    view_choseAgeBG = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight-200, kScreenWidth, 200)];
    [self.view addSubview:view_choseAgeBG];
    view_choseAgeBG.backgroundColor = COLOR_EVERYVIEWBG;
    
    //cancel  sure
    self.buttonView = [[UIView alloc] initWithFrame:CGRectMake(0,0, kScreenWidth, 40)];
    [view_choseAgeBG addSubview:self.buttonView];
    self.buttonView.backgroundColor = COLOR_EVERYVIEWBG;
    
    //picker
    self.datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,self.buttonView.bottom, kScreenWidth, 160)];
    [view_choseAgeBG addSubview:self.datePicker];

    self.datePicker.datePickerMode = UIDatePickerModeDate;//日期
    self.datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"];
    
    //cancel
    UIButton *button_cancel = [[UIButton alloc] initWithFrame:CGRectMake(0,0, self.buttonView.width/2, self.buttonView.height)];
    [self.buttonView addSubview:button_cancel];
    [button_cancel setTitle:@"取消" forState:UIControlStateNormal];
    [button_cancel setTitleColor:COLOT_TEXTGRAY forState:UIControlStateNormal];
    [button_cancel addTarget:self action:@selector(cancelPick:) forControlEvents:UIControlEventTouchUpInside];
    //sure
    UIButton *button_sure = [[UIButton alloc] initWithFrame:CGRectMake(button_cancel.right,0, self.buttonView.width/2, self.buttonView.height)];
    [self.buttonView addSubview:button_sure];
    [button_sure setTitle:@"确定" forState:UIControlStateNormal];
    [button_sure setTitleColor:COLOT_TEXTGRAY forState:UIControlStateNormal];
    [button_sure addTarget:self action:@selector(confirmPick:) forControlEvents:UIControlEventTouchUpInside];
}

//移除背景 视图
- (void) removeChoseAgeBGBgView
{
    [view_cover removeFromSuperview];
    [view_choseAgeBG removeFromSuperview];
}

#pragma mark -- picker delegate
- (void) pickViewdelegateWith:(NSString *)messStr andRow:(int)rowIndex andSelectecRow:(int)selectedRow
{

    if (rowIndex==1) {
        
        [self.dic_xinfoAll setObject:messStr forKey:@"nationality"];
    }
    
    if (rowIndex==2) {
        
        int educationlevel = 0;
        //学历
        if ([messStr isEqualToString:@"硕士及以上"]) {
            educationlevel = 1;
        }
        if ([messStr isEqualToString:@"本科"]) {
            educationlevel = 2;
        }
        if ([messStr isEqualToString:@"大专"]) {
            educationlevel = 3;
        }
        if ([messStr isEqualToString:@"高中/中专"]) {
            educationlevel = 4;
        }
        if ([messStr isEqualToString:@"初中及以下"]) {
            educationlevel = 5;
        }
        [self.dic_xinfoAll setValue:[NSNumber numberWithInt:educationlevel] forKey:@"educationlevel"];
    }
    if (rowIndex==3) {
        //婚姻
        int ismarriage = 0;
        if ([messStr isEqualToString:@"未婚"]) {
            ismarriage = 1;
        }
        if ([messStr isEqualToString:@"已婚"]) {
            ismarriage = 2;
        }
        [self.dic_xinfoAll setValue:[NSNumber numberWithInt:ismarriage] forKey:@"ismarriage"];
    }
    if (rowIndex==4) {
        
        //证件
        int cardtype = 0;
        if ([messStr isEqualToString:@"身份证"]) {
            cardtype = 1;
        }
        if ([messStr isEqualToString:@"护照"]) {
            cardtype = 2;
        }
        if ([messStr isEqualToString:@"军官证"]) {
            cardtype = 3;
        }
        if ([messStr isEqualToString:@"港澳台证件"]) {
            cardtype = 4;
        }
        if ([messStr isEqualToString:@"其他证件"]) {
            cardtype = 5;
        }
        
        NSLog(@"cardtype%d",cardtype);

        [self.dic_xinfoAll setValue:[NSNumber numberWithInt:cardtype]  forKey:@"cardtype"];
    }
    
    [self.mutableArray_content replaceObjectAtIndex:rowIndex withObject:messStr];

    [self.tableView_fillInfo reloadData];
}

//选择则性别
- (void)choseSexManOrWoman:(UIButton *)sender
{
    NSLog(@"dddddd");
    //    性别，0女1男
    if (sender.tag==33)
    {
        pathSex = 1;
        [self.dic_xinfoAll setObject:[NSNumber numberWithInt:pathSex] forKey:@"sex"];
         [button_man setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
        [button_woman setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
    }
    else
    {
        pathSex = 0;
        
        [self.dic_xinfoAll setObject:[NSNumber numberWithInt:pathSex] forKey:@"sex"];
        
        [button_man setImage:[UIImage imageNamed:@"unselected"] forState:UIControlStateNormal];
        [button_woman setImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
    }
    
}

#pragma mark --- 确定 取消
- (void)cancelPick:(id)sender {

    view_choseAgeBG.hidden = YES;
}

- (void)confirmPick:(id)sender {
    //获取日期
    NSDateFormatter *formatter =[[NSDateFormatter alloc] init];
    formatter.dateFormat = @"YYYY-MM-dd";
    
    NSString *timestamp = [formatter stringFromDate:self.datePicker.date];
    
    if (recordChoseWhoTime==0) {
        [self.dic_xinfoAll setObject:timestamp forKey:@"brithday"];
        
        [self.mutableArray_content replaceObjectAtIndex:0 withObject:timestamp];
    }
    if (recordChoseWhoTime==1) {
        
        NSLog(@"timestamp%@",timestamp);

        // 有 日期
        if ([self.dic_xinfoAll[@"cardtime"] containsString:@"-"]) {
            NSString *str_temp = [self.dic_xinfoAll[@"cardtime"] substringFromIndex:10];
            
            [[timestamp stringByReplacingOccurrencesOfString:@"-" withString:@"."] stringByAppendingString:str_temp];
                        
            [self.dic_xinfoAll setObject:[[timestamp stringByReplacingOccurrencesOfString:@"-" withString:@"."] stringByAppendingString:str_temp] forKey:@"cardtime"];
            
            [self.tableView_fillInfo reloadData];
            
            [self.view endEditing:NO];
            view_choseAgeBG.hidden = YES;
            
            return;

        }
        else
        {
            //无日期
             [self.dic_xinfoAll setObject:[timestamp stringByReplacingOccurrencesOfString:@"-" withString:@"."] forKey:@"cardtime"];
        }
    }
    
    if (recordChoseWhoTime==2) {
        // 有 日期
        
        NSString *str_temp = [self.dic_xinfoAll[@"cardtime"] substringToIndex:11];
        [str_temp stringByAppendingString:[timestamp stringByReplacingOccurrencesOfString:@"-" withString:@"."]];
        
        [self.dic_xinfoAll setObject:[str_temp stringByAppendingString:[timestamp stringByReplacingOccurrencesOfString:@"-" withString:@"."]] forKey:@"cardtime"];
    }
    else
    {
        //无日期
        [self.dic_xinfoAll setObject:[self.dic_xinfoAll[@"cardtime"] stringByAppendingString:[timestamp stringByReplacingOccurrencesOfString:@"-" withString:@"."]] forKey:@"cardtime"];
    }

    [self.tableView_fillInfo reloadData];
    
    [self.view endEditing:NO];
    view_choseAgeBG.hidden = YES;
}

#pragma mark --- 下一步
- (void) doNextAction
{
    if (pathSex==2) {
        [UIView showAlertMsg:@"请选择性别"];
        return;
    }

//    if (!self.dic_xinfoAll && [self.mutableArray_content containsObject:@"填写"] ) {
//        [UIView showAlertMsg:@"请完善信息"];
//        return;
//    }
    
//    if ([self.mutableArray_content containsObject:@"填写"] ) {
//        [UIView showAlertMsg:@"请完善信息"];
//        return;
//    }
    
    [self.mutableArray_content insertObject:textField_name.text atIndex:0];
    
    SupplementaryInformationVC *supplementView = [[SupplementaryInformationVC alloc] init];
    supplementView.mutableArray_fillDataPath = self.mutableArray_content;
    
    supplementView.dic_pathPersonInfo = self.dic_xinfoAll;
    
    [self.navigationController pushViewController:supplementView animated:NO];
}

#pragma mark -- 网络数据请求
- (void) DataSourceRequestMemberXinfoView
{
    Reachability *reach = [Reachability reachabilityForInternetConnection];
    NetworkStatus status = [reach currentReachabilityStatus];
    
    if (![UIView NetFromStatus:status]) {
        NSLog(@"没有网络");
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        [UIView showAlertMsg:@"网络连接已断开" andShowBgColor:[UIColor blackColor] andLabelTectColor:[UIColor whiteColor]];
        
        return;
    }
    else
    {
        NSString *strUrl = [NSString stringWithFormat:@"%@member/xinfo",MRAPI];
        NSDictionary *paras_info = @{@"memberid":[[NSUserDefaults standardUserDefaults] objectForKey:@"memberid"]};
        [[HttpRequest shardWebUtil] getNetworkRequestURLString:strUrl parameters:paras_info success:^(id obj) {
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            
            NSLog(@"xinfo%@",obj);
            
            NSString *str_false = obj[@"error"];
            if (str_false.length==0) {
                self.dic_xinfoAll = [[NSMutableDictionary alloc] init];
                self.dic_xinfoAll = [obj mutableCopy];
                
                if (self.dic_xinfoAll[@"sex"]) {
                    pathSex = [self.dic_xinfoAll[@"sex"] intValue];
                }
                else
                {
                 pathSex = 2;//标记 性别
                }

                [self.tableView_fillInfo reloadData];
            }
            else
            {
                [UIView showAlertMsg:str_false];
            }
            
        } fail:^(NSError *error) {
            NSLog(@"error%@",error);
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            [UIView showAlertMsg:@"网络请求超时"];
        }];
        
    }
}

- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

#pragma mark keyboardNotification

- (void)keyboardWillShow:(NSNotification*)notification{
    
    if (isEditName==NO)
    {
        CGRect _keyboardRect = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
        
        //如果self在键盘之下 才做偏移
        if ([self convertYToWindow:CGRectGetMaxY(self.tableView_fillInfo.frame)]>=_keyboardRect.origin.y)
        {
            //没有偏移 就说明键盘没出来，使用动画
            if (self.view.frame.origin.y== self.tableView_fillInfo.frame.origin.y) {
                
                [UIView animateWithDuration:0.3 animations:^{
                    self.view.frame = CGRectMake(0, -_keyboardRect.size.height+[self getHeighOfWindow]-CGRectGetMaxY(self.view.frame), kScreenWidth, kScreenHeight);
                }];
            }
            else
            {
                self.view.frame = CGRectMake(0,0, kScreenWidth, kScreenHeight);
            }
        }
    }
}

- (void)keyboardWillHide:(NSNotification*)notification{
    
    [UIView animateWithDuration:0.3 animations:^{
        self.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    }];
}

#pragma  mark ConvertPoint
//将坐标点y 在window和superview转化  方便和键盘的坐标比对
-(float)convertYFromWindow:(float)Y
{
    AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    CGPoint o = [appDelegate.window convertPoint:CGPointMake(0, Y) toView:self.view];
    return o.y;
    
}
-(float)convertYToWindow:(float)Y
{
    AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    CGPoint o = [self.view convertPoint:CGPointMake(0, Y) toView:appDelegate.window];
    return o.y;
    
}
-(float)getHeighOfWindow
{
    AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    return appDelegate.window.frame.size.height;
}

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
